package com.chare.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chare.mapper.DepartmentMapper;
import com.chare.pojo.Department;
import com.chare.pojo.RespBean;
import com.chare.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author shi
 * @since 2022-06-17
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {
@Autowired
private DepartmentMapper mapper;
    @Override
    public List<Department> getAll() {
        return mapper.getAll(-1);
    }

    @Override
    public RespBean addDep(Department department) {
        department.setEnabled(true);
        mapper.addDep(department);
        if(1==department.getResult())
        {
            return RespBean.success("添加成功",department);
        }
        return RespBean.error("添加失败");
    }

    @Override
    public RespBean deleteDe(Integer id) {
        Department department=new Department();
        department.setId(id);
        mapper.deleteDe(department);
if(department.getResult()==-2)
{
    return RespBean.error("该部门下有子部门");
}
if(department.getResult()==-1)
{
    return RespBean.error("该部门下有员工");
}
if(department.getResult()==1)
{
    return RespBean.success("删除成功");
}
return RespBean.success("删除失败");

    }


}
